﻿using System;
using System.Threading;
using Skynet.Contracts.Capture;
using Skynet.Contracts;
using System.Runtime.InteropServices;
namespace Transport
{
    /// <summary>
    /// RawVideoTransport
    /// </summary>
    public class RawVideoTransport : IVideoTransport
    {
        private ITransport _transport;

        public RawVideoTransport(ITransport transport)
        {
            if (transport == null)
                throw new ArgumentNullException("transport");
            _transport = transport;
        }

        public void Dispose() { }

        public void EncodeAndTransmit(IntPtr buffer, int bufferLen)
        {
            //Console.Write("v");
            //Thread.Sleep(10);
            var data = new byte[bufferLen];
            Marshal.Copy(buffer, data, 0, bufferLen);
            _transport.Transmit(new VideoFrame
            {
                Data = data
            });
        }
    }
}
